package gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.util.Observable;

import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.JScrollBar;

import processing.core.PApplet;

/**
 * 
 * @author Chrystopher
 * Inner views of the main view. Must implement IView interface to observe a passed-in model.
 * (Observer pattern).
 * Must also be instanciated with a JPanel (CView Panel).
 */

public class ConcreteView extends JInternalFrame implements IView{

	/*
	 * Concrete View gui attributes.
	 */
	
	private CViewPanel cPanel;
	private JPanel panel;
	public PApplet embeddedApplet;
	public final int PAPPLET_PREF_WIDTH = 800, PAPPLET_PREF_HEIGHT = 600;
	
	public ConcreteView(CViewPanel cPanel){
		this.cPanel = cPanel;
		display();
	}
	
	public ConcreteView(CViewPanel cPanel, String concreteViewName){
		this.cPanel = cPanel;
		setTitle(concreteViewName);
		
		display();
		
		setLayout(new BorderLayout());
		embeddedApplet = new BuildingSketchView();
        
        cPanel.add(embeddedApplet);
        add(cPanel,BorderLayout.EAST);
                

        setPreferredSize(new Dimension(PAPPLET_PREF_WIDTH,PAPPLET_PREF_HEIGHT));
        
        // important to call this whenever embedding a PApplet.
        // It ensures that the animation thread is started and
        // that other internal variables are properly set.
        embeddedApplet.init();
        cPanel.requestFocus(true);
        
	}
	

	public void update(Observable arg0, Object arg1) {
		// TODO Auto-generated method stub
		
	}

	public void display() {
		if(getTitle().isEmpty()){
			setTitle("Generic Concrete View");
		}
		/*
		 * Make concrete view visible and all default parameters.
		 */
		setClosable(false);
		
		setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
		setVisible(true);
	}

	public PApplet getEmbeddedApplet() {
		return embeddedApplet;
	}

	public void setEmbeddedApplet(PApplet embeddedApplet) {
		this.embeddedApplet = embeddedApplet;
	}

	public JPanel getViewPanel() {
		return cPanel;
	}

	public void setViewPanel(CViewPanel panel) {
		this.cPanel = panel;
	}

}
